package test2.experiment6;

import java.util.HashMap;
import java.util.Scanner;

public class WeekExceptionTest {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个1~7的数字：");
        int week = scanner.nextInt();
        try {
            System.out.println(IntWeekToStringWeek(week));
        } catch (WeekException e) {
            e.printStackTrace();
        }
        scanner.close();
    }

    public static String IntWeekToStringWeek(int week) throws WeekException {
        HashMap<Integer, String> map = new HashMap<Integer, String>();
        map.put(1, "周一");
        map.put(2, "周二");
        map.put(3, "周三");
        map.put(4, "周四");
        map.put(5, "周五");
        map.put(6, "周六");
        map.put(7, "周七");
        String s = map.get(week);
        if (s == null) {
            throw new WeekException("请输入1~7之间的数字", week);
        } else {
            return map.get(week);
        }
    }
}

class WeekException extends Exception {
    static final long serialVersionUID = 1586415645645646449L;
    private int week;

    public WeekException(String message, int week) {
        super(message);
        this.week = week;
    }

    public int getWeek() {
        return week;
    }
}
